import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/login"
  },
  {
    path: '/login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/index',
    component: () => import('../views/IndexView.vue'),
    children:[
      { path: "hello", name: "hello", component: () => import("../components/HelloWorld.vue") },
      // wenzhiyi
      { path: "bodytypepe", name:'体质测评', component: () => import("../components/wenzhiyi/Bodytypepe.vue") },
      { path: "mentalityresult", name:'心理测评', component: () => import("../components/wenzhiyi/Mentalityresult.vue") },
      { path: "interposeclassify", name:'人群分类', component: () => import("../components/wenzhiyi/Interposeclassify.vue") },
      { path: "scheme", name:'模版管理', component: () => import("../components/wenzhiyi/Scheme.vue") },
      { path: "interposescheme", name:'干预方案', component: () => import("../components/wenzhiyi/Interposescheme.vue") },
      { path: "dingzhifangan", name:'定制方案', component: () => import("../components/wenzhiyi/DingZhiFangAn.vue") },
      { path: "interposefollowupvisit", name:'随访日记', component: () => import("../components/wenzhiyi/Interposefollowupvisit.vue") },


      
        
      // tankai
      { path: 'table', name:'会员档案', component: () => import('../components/tankai/MeTableViem.vue')},
      { path: 'tjsc', name:'体检上传', component: () => import('../components/tankai/TjscTableViem.vue')},
      { path: 'menu', name:'菜单管理', component: () => import('../components/tankai/MenuView.vue')},
      { path: 'user', name:'用户管理', component: () => import('../components/tankai/UserView.vue')},
      { path: 'gzt', name:'工作台', component: () => import('../components/GztView.vue')},
      { path: 'hytj', name:'会员统计', component: () => import('../components/tankai/hytjView.vue')},



      // liuyunan
      { path: "appointment", name: "预约列表", component: () => import("../components/liuyunan/appointment.vue") },
      { path: "checklist", name: "检查项管理", component: () => import("../components/liuyunan/checklist.vue") },
      { path: "setmeal", name: "套餐管理", component: () => import("../components/liuyunan/setmeal.vue") },
      { path: "sportsItemLibrary", name: "运动项目库", component: () => import("../components/liuyunan/sportsItemLibrary.vue") },
      { path: "meals", name: "膳食库", component: () => import("../components/liuyunan/meals.vue") },
      { path: "diseaseLibrary", name: "疾病库", component: () => import("../components/liuyunan/diseaseLibrary.vue") },
      { path: "orderDate", name: "预约设置", component: () => import("../components/liuyunan/orderDate.vue") },
      { path: "analysisView", name: "统计分析", component: () => import("../components/liuyunan/analysisView.vue") },


   
    ]
  },
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//路由后置守卫
router.afterEach((to) => {
  let menpath = []
  //如果breadcrumbNames是空的，就不需要传递参数
  if (!to.query.menusText) {
    //调用veux中mutations中的方法
    router.app.$store.commit("getBreadcrumbNames")
  } else {
     //如果breadcrumbNames是不是空值
    if (to.query.menusText.length != 0) {
      //根据逗号分隔字符串
      menpath = to.query.menusText.split(",")
      //调用veux中mutations中的方法，并传递参数
      router.app.$store.commit("getBreadcrumbNames", menpath)
    } 
  }
})

export default router
